<?php
	if(!isset($saved) || $saved == false)
	{?>
<?php if(!isset($savedFail)){ ?>
	<div id="moduleEditBlock">
<?php }?>
	<?php $formId = "moduleEdit";
		ClassRegistry::getObject('Module')->setFieldProperties('section',array('disabled'=>true));
		echo $form->create("Module",array('id'=>$formId,'url'=>"/".$this->params['url']['url']));
		echo $this->element('module_tabs');
		echo $form->end(__("Save"));
?>
<script type="text/javascript">
$(document).ready(function(){
	<?php if(isset($changeModuleType)){?>
	$("#ModuleName").change(function(){
		 $.get(URL+"/admin/modules/getParams/"+$("#ModuleName").val(), function(data){
				$("#params").html(data);
			});
		});
	<?php }?>
	options = {
			'formResponse': 'followRedirect',
			'onSuccess': false,
			'datatype': 'text',
			'beforeSubmit':false,
			'responseArea': '#moduleEditBlock'
		};
	GigaAjaxForm.init("<?php echo $formId?>",options);
})
</script>
<?php if(!isset($savedFail)){ ?>
</div>
<?php }?>
<?php }else
	{
		$sectionsOutput = array();
		$sectionOutput = $section->render($module['Module']['section']);
		$sectionsOutput[$module['Module']['section']] = $sectionOutput;
?>
<script>

	var newSections = <?php echo $javascript->object($sectionsOutput);?>;
	for(var sectionId in newSections )
	{
			sectionHmtl = newSections[sectionId];
			SectionManagerObject.getSectionById(sectionId).getDom().replaceWith(sectionHmtl);
			
	}
	SectionManagerObject.rebuild();
	tb_remove();
</script>
<?php	}
?>